//--------------------------------------------------------------------------------
// Alec G Thilenius
//
// This software is distributed under the MIT License, available at the following
// URL:
// http://www.opensource.org/licenses/mit-license.php
//--------------------------------------------------------------------------------

#pragma once

#include "PCH.h"
#include "Edge.h"
#include "Graph.h"

namespace AlecThilenius
{
	class Vertex
	{
	public:
		~Vertex(void);

		//-------------------    Name      ---------------------
		const std::string&	GetName	() const;

		//-------------------    Getters   ---------------------
		EdgePtr GetEdgeTo			(const VertexPtr vertex);
		const void GetAllEdges		(EdgePtr* edges, int* count);

		double GetWieghtToVertex	(const VertexPtr vertex);
		void SetWeightToVertex		(const VertexPtr, double weight);

		//-------------------    Create    ---------------------
		EdgePtr CreateEdgeTo		(const VertexPtr vertex, double weight);
		
		//-------------------    Remove    ---------------------
		bool RemoveEdgeTo			(const VertexPtr vertex);

		//-------------------    Multi     ---------------------
		void RemoveAllEdgeTails		();
		void RemoveAllEdges			();

		//-------------------    Streaming ---------------------
		void Print			( std::ostream& oS );

	private:
		//------------   Private constructor  -----------------
		Vertex(std::string name, Graph* graphRef);

		//-------------------   Typedef    ---------------------
		typedef std::unordered_map<std::string, EdgePtr> EdgeMap;
		typedef EdgeMap::iterator EdgeMapIter;

		typedef std::unordered_map<std::string, VertexPtr> HeadSet;
		typedef HeadSet::iterator HeadSetIter;

		//-------------------   Member     ---------------------
		std::string m_name;
		std::weak_ptr<Vertex> m_sharedResource;

		EdgeMap m_edgeMap;
		HeadSet m_headSet;

		Graph* m_graphRef;

		//-------------------   Friends    ---------------------
		friend Graph;

	};
};

//-------------------   Stream forward Declaration    ---------------------
std::ostream& operator << ( std::ostream& stream, AlecThilenius::Vertex& vertex );